﻿@{
    ViewData["Title"] = "RoadFlow工作流-.NET CORE工作流引擎";
}
<style type="text/css">
    html, body { overflow: hidden; }
</style>
<script src="~/RoadFlowResources/scripts/signalr.js"></script>
<script type="text/javascript">
    $(window).load(function () {
        try {
            connection = new signalR.HubConnectionBuilder().withUrl("/SignalRHub").build();
            //.configureLogging(signalR.LogLevel.Information)
            connection.start();
            connection.on("SendMessage", function (user, message) {
                showMessage(message);
            });
        } catch (e) { }
    });
    var messageId = "";
    function showMessage(data) {
        var html = "";
        try {
            json = JSON.parse(data);
            id = json.id || "";
            messageId = id;
            if (json.title && json.title.length > 0) {
                $("#messagetitle").html("<i class='fa fa-bell-o' style='margin-right:3px;font-size:14px;'></i>"+json.title);
            }
            else {
                $("#messagetitle").html("<i class='fa fa-bell-o' style='margin-right:3px;font-size:14px;'></i>未读消息");
            }
            html = '<div>' + json.contents + '</div>';
            if (json.count) {
                html += '<div style="margin-top:8px;"><a class="blue1" href="javascript:void(0);" onclick="openApp(\'/RoadFlowCore/Message/NoRead\',0,\'未读消息\',\'noreadmessage\');closeMessage(\'' + id + '\');return false;">您有' + json.count + '条未读消息，点击查看。</a></div>';
            }
        }
        catch(e)
        {
            html = "";
        }
        if (html.length > 0) {
            $("#messagecontent").html(html);
            $("#message").hide().slideDown(800);
        }
    }
    function closeMessage(id) {
        id = id || messageId;
        $("#message").hide(400);
        if (id && id.length > 0) {
            $.ajax({ url: "/RoadFlowCore/Message/UpdateRead", data: { "ids": id }, type:"POST" });
        }
    }
</script>
<div class="homemsgdiv" id="message">
    <div class="homemsgdivtitlediv">
        <div class="homemsgdivtitlediv1"></div>
        <div class="homemsgdivtitlediv1bg">
            <div class="homemsgdivtitlediv1bgtitle" id="messagetitle"></div>
            <div class="homemsgdivtitlediv1bgclose" onclick="closeMessage();"></div>
        </div>
    </div>
    <div class="homemsgdivmsg" id="messagecontent"></div>
</div>
<div class="mainTop">
    <div class="mainTopLeft"></div>
    <div class="mainTopRight">
        <div style="padding-right:10px; padding-top:7px;">
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td rowspan="2" valign="middle" style="vertical-align:middle; padding-right:10px;">
                        <img src="@ViewData["headImage"]" width="45" height="45" id="UserHeadImg" style="vertical-align:middle;border-radius:38px" />
                    </td>
                    <td style="text-align:left;">
                        <div>
                            <span>欢迎您：@ViewData["userName"]</span>
                            <span style="margin-right:6px;"></span>
                            <span style="margin-right:6px;">今天是：<span id="CurrentDateTimeSpan">@ViewData["currentDate"]</span></span>
                            <span style="">主题：</span>
                            <span class="mainTheme_blue" onclick="changeTheme('Blue', true);"></span>
                            <span class="mainTheme_green" onclick="changeTheme('Green', true);"></span>
                            <span class="mainTheme_gray" onclick="changeTheme('Gray', true);"></span>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:left;">
                        <div style="margin-top:6px;">
                            <span style="margin-right:4px;"><a href="http://www.roadflow.net" class="white" target="_blank">官方网站</a></span>
                            <span style="margin-right:6px;">|</span>
                            <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('/Home/Home',0,'首页','index'); return false;" class="white">平台首页</a></span>
                            <span style="margin-right:6px;">|</span>
                            <span style="margin-right:6px;"><a href="javascript:void(0);" onclick="openApp('/RoadFlowCore/UserSet/EditPass',2,'修改密码','index_editpass',500,210); return false;" class="white">修改密码</a></span>
                            <span style="margin-right:6px;">|</span>
                            <span style="margin-right:4px;"><a href="javascript:void(0);" onclick="if(confirm('您真的要退出系统吗?')){window.location='/Home/Quit';} return false;" class="white">退出系统</a></span>
                        </div>
                    </td>
                </tr>
            </table>
        </div>

    </div>
    <div style="clear:both;"></div>
</div>
<div class="mainDiv">
    <table cellpadding="0" cellspacing="0" width="100%" border="0">
        <tr>
            <td class="mainMenutd" id="mainMenutd" style="display:none;">
                <table cellpadding="0" cellspacing="0" width="100%" border="0">
                    <tr>
                        <td class="menutd">
                            <div class="menuDiv">
                                <div class="menuDivRightTitle">
                                    <div style="float:left; padding-left:7px;"><i class="fa fa-navicon menuTopIco" style="font-size:14px;"></i>管理菜单</div>
                                    <div class="menuswitchleft" onclick="switchMenu(this,0);"><i class="fa fa-angle-double-left"></i></div>
                                </div>
                            </div>
                        </td>
                        <td valign="top" style="vertical-align:top;">
                            <div class="mainSplittdImg">

                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" colspan="2" class="menutd1" style="vertical-align:top;">
                            <div class="menuDivRight" style="clear:both;">
                                <div style="overflow:hidden;">
                                    <div id="treeDiv" style="margin:0;width:195px;overflow:auto; overflow-x:hidden;">
                                        @Html.Raw(ViewData["menu"])
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width:60px; display:none;vertical-align:top;" id="mainMenutd1">
                <table cellpadding="0" cellspacing="0" width="100%" border="0">
                    <tr>
                        <td class="menutd" style="width:40px;">
                            <div class="menuDiv">
                                <div class="menuDivRightTitle">
                                    <div class="menuswitchright" onclick="switchMenu(this,1);"><i class="fa fa-angle-double-right"></i></div>
                                </div>
                            </div>
                        </td>
                        <td valign="top">
                            <div class="mainSplittdImg">

                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top" colspan="2" class="menutd1" style="vertical-align:top;">
                            <div class="menuDivRight" style="clear:both;width:60px;">
                                <div style="overflow:hidden;">
                                    <div id="treeDiv1" style="margin:0;overflow:auto; overflow-x:hidden;">
                                        @Html.Raw(ViewData["menumin"])
                                    </div>
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="vertical-align:top;" valign="top">
                <div class="tab_top"></div>
                <div id="mainTabDiv" class="mainTabDiv"></div>
            </td>
        </tr>
    </table>
</div>
<script type="text/javascript">
    var mainTab = null;
    var mainTree = null;
    var mainDialog = new RoadUI.Window();
    var userID = '';
    var rootdir = '@ViewData["rootDir"]';
    var roadflowCurrentWindow = null;//当前操作窗口对象
    var lastURL = "";//最后操作的页面地址
    var scrollParams = { cursorcolor: "#ACACAC", autohidemode: "leave", horizrailenabled: true };
    $(function () {
        $.cookies.set("rf_core_rootdir", rootdir, { expiresAt: new Date(2099, 1, 1) });
        //从cookie读取用户上次的菜单类型并设置
        var usermenutype = $.cookies.get("usermenutype");
        if ("1" == usermenutype) {
            switchMenu($(".menuswitchright"), 1);
        }
        else if ("0" == usermenutype) {
            switchMenu($(".menuswitchleft"), 0);
        }
        else {
            if ($(window).width() < 1024)//屏幕宽度小于1024显示窄菜单模式
            {
                switchMenu($(".menuswitchright"), 0);
            }
            else {
                switchMenu($(".menuswitchright"), 1);
            }
        }
        //菜单类型设置完成
        var windowheight = $(window).height() - 64;
        $('#mainTabDiv').height(windowheight - 3);
        $('.menuDivLeft').height(windowheight);
        $('.menuDivRight').height(windowheight);
        $('.menuDivRight>div>div').height(windowheight - 38);

        $(window).bind('resize', function () {
            var height = $(window).height() - 64;
            $('#mainTabDiv').height(height - 3);
            $('.menuDivLeft').height(height);
            $('.menuDivRight').height(height);
            $('.menuDivRight>div>div').height(height - 38);
            mainTab.topResize(height);
            $("#treeDiv").getNiceScroll().resize(scrollParams);
        });

        mainTab = new RoadUI.Tab({ id: "mainTabDiv", replace: true });
        openApp("/Home/Home", 0, "首页", "INDEX");

        //初始化主题按钮样式
        var theme = $.cookies.get("rf_core_theme") || "blue";
        changeTheme(theme, false);

        //初始显示未读消息
        try {
            var noReadMsgJson = JSON.stringify(@Html.Raw(ViewData["noReadMsgHtml"]));
            if (noReadMsgJson && noReadMsgJson.length > 0) {
                showMessage(noReadMsgJson);
            }
        }
        catch (e) { }

        var nice = $("#treeDiv").niceScroll(scrollParams);
        var nice1 = $("#treeDiv1").niceScroll(scrollParams);
    });

    //宽菜单点击事件
    function menuClick(div, isref1) {
        var $div = $(div);
        var id = $div.attr("data-id");
        var title = $div.attr("data-title");
        var url = $div.attr("data-url");
        var model = $div.attr("data-model");
        var width = $div.attr("data-width");
        var height = $div.attr("data-height");
        var childs = $div.attr("data-childs");

        if (0 == isref1) {
            $("#treeDiv .menulistdivhover").removeClass().addClass("menulistdiv");
        }
        else {
            $(".menulistdivhover").removeClass().addClass("menulistdiv");
        }
        $div.removeClass().addClass("menulistdivhover");
        if ("1" == childs) {
            addChildMenu(id, $div, isref1);
        }
        else if (1 == isref1) {
            $(".menulistdiv11sub").hide();//小菜单时点击后隐藏菜单
        }
        if ($.trim(url.length) > 0) {
            openApp(url, model, title, id, parseInt(width), parseInt(height), true);
        }
    }

    //小菜单点击事件
    function menuClick1(div) {
        var $div = $(div);
        var id = $div.attr("data-id");
        var title = $div.attr("data-title");
        var url = $div.attr("data-url");
        var model = $div.attr("data-model");
        var width = $div.attr("data-width");
        var height = $div.attr("data-height");
        var childs = $div.attr("data-childs");
        $(".menulistdiv11hover").removeClass().addClass("menulistdiv11");
        $div.removeClass().addClass("menulistdiv11hover");
        if ("1" == childs) {
            addChildMenu1(id, $div);
        }
        else {
            $(".menulistdiv11sub").hide();
        }

        if ($.trim(url.length) > 0) {
            openApp(url, model, title, id, parseInt(width), parseInt(height), true);
        }
    }

    var parentCount = 0;
    var childMenuDivs = [];
    var isLoadMenu = true;//防止重复加载
    //isref1 1为小菜单 0为大菜单
    function addChildMenu(id, $div, isref1) {
        var $childs = 1 == isref1 ? $("[data-parent='" + id + "'][data-isrefresh1='1']") : $("#treeDiv [data-parent='" + id + "']");
        var $loadDiv = $(".menulistdiv2 i", $div);
        if ($childs.size() == 0 && isLoadMenu) {
            //$loadDiv.removeClass().addClass("fa fa-spinner");
            isLoadMenu = false;
            parentCount = 0;
            getParentCount($div.attr("data-parent"), isref1);
            parentCount++;
            var paddingLeft = parentCount * 11;
            $.ajax({
                url: rootdir + "/Home/MenuRefresh1?refreshid=" + id + "&isrefresh1=" + (1 == isref1 ? "1" : "0"), async: false, cache:false, success: function (html) {
                    if (html.indexOf('loginstatus') >= 0 && -1 == JSON.parse(html).loginstatus) {
                        login();
                    }
                    var $html = $(html);
                    $(".menulistdiv1", $html).css("padding-left", paddingLeft.toString() + "px");
                    $div.after($html);
                    $loadDiv.removeClass().addClass("fa fa-angle-down");
                    isLoadMenu = true;
                }
            });
        }
        else {
            var cls = $loadDiv.attr("class");
            var isClose = true;
            if ("fa fa-angle-down" == cls) {
                $loadDiv.removeClass().addClass("fa fa-angle-left");
            }
            else {
                $loadDiv.removeClass().addClass("fa fa-angle-down");
                isClose = false;
            }
            childMenuDivs = new Array();
            for (var i = 0; i < $childs.size(); i++) {
                if (isClose) {
                    $childs.eq(i).hide();
                }
                else {
                    $childs.eq(i).show();
                }
                addAllChilds($childs.eq(i).attr("data-id"), isref1);
            }
            for (var i = 0; i < childMenuDivs.length; i++) {
                if (isClose) {
                    childMenuDivs[i].attr("data-show", childMenuDivs[i].is(':visible') ? "1" : "0");
                    childMenuDivs[i].hide();
                }
                else {
                    if ("1" == childMenuDivs[i].attr("data-show")) {
                        childMenuDivs[i].show();
                    }
                }
            }
        }
        $("#treeDiv").getNiceScroll().resize(scrollParams);
    }

    function addChildMenu1(id, $div) {
        $(".menulistdiv11sub").hide();
        var $childs = $(".menulistdiv11sub[data-parent='" + id + "']");
        if ($childs.size() == 0 && isLoadMenu) {
            isLoadMenu = false;
            parentCount = 0;
            getParentCount($div.attr("data-parent"), 1);
            parentCount++;
            var paddingLeft = parentCount * 11;
            $.ajax({
                url: rootdir + "/Home/MenuRefresh1?refreshid=" + id + "&isrefresh1=1", async: true, cache: false, success: function (html) {
                    if (html.indexOf('loginstatus') >= 0 && -1 == JSON.parse(html).loginstatus) {
                        login();
                    }
                    var $html = $(html);
                    var $menuDiv = $('<div class="menulistdiv11sub" data-parent="' + id + '"></div>');
                    var left = $div.position().left + 55;
                    var top = $div.position().top - 1;
                    $menuDiv.append($html);
                    $(document.body).append($menuDiv);
                    if (($menuDiv.height() + top) > $("#treeDiv1").height()) {
                        top = top - $menuDiv.height() + $div.height();
                    }
                    $menuDiv.css("left", left);
                    $menuDiv.css("top", top);
                    $menuDiv.niceScroll(scrollParams);
                    isLoadMenu = true;
                }
            });
        }
        else {
            $childs.show();
        }
    }

    function addAllChilds(id, isref1) {
        var $divs = 1 == isref1 ? $("[data-parent='" + id + "'][data-isrefresh1='1']") : $("#treeDiv [data-parent='" + id + "']");
        if ($divs.size() > 0) {
            for (var i = 0; i < $divs.size(); i++) {
                childMenuDivs.push($divs.eq(i));
                addAllChilds($divs.eq(i).attr("data-id"));
            }
        }
    }

    function getParentCount(parentId, isref1) {
        var $divs = 1 == isref1 ? $("[data-id='" + parentId + "'][data-isrefresh1='1']") : $("#treeDiv [data-id='" + parentId + "']");
        if ($divs.size() > 0) {
            parentCount++;
            var pid = $divs.first().attr("data-parent");
            if (pid && pid.length > 0) {
                getParentCount(pid);
            }
        }
    }

    function treeClick(json) {
        if (json) {
            openApp(json.link, json.model, json.title, json.id, parseInt(json.width), parseInt(json.height), true);
        }
    }

    //url 应用地址
    //model 0标签方式 1弹出层 2弹出层（模态）3弹出窗口 4弹出窗口（模态) 5新窗口
    //title 标题
    //id 打开应用的ID
    //width 宽度，弹出层和弹出窗口时有用
    //height 高度，弹出层和弹出窗口时有用
    //isAppendParams 是否自动向地址添加appid参数
    //openerId 打开方式为弹出层时的openerid
    //openerWindow 打开方式为弹出窗口时的window对象
    //setTopWindow 是否要设置top.roadflowCurrentWindow
    function openApp(url, model, title, id, width, height, isAppendParams, openerId, openerWindow, setTopWindow) {
        if (!url || url.toString().length == 0) {
            return;
        }
        if (!id) {
            id = RoadUI.Core.queryString("tabid", url);
            if (id) {
                id = id.replace("tab_", "");
            }
        }
        if (!id) {
            id = RoadUI.Core.newid();
        }
        if (setTopWindow == undefined)
        {
            setTopWindow = true;
        }
        id = id.toUpperCase();
        if (width == 0) width = undefined;
        if (height == 0) height = undefined;
        if (isAppendParams) {
            url += url.indexOf('?') >= 0 ? "&appid=" + id : "?appid=" + id;
        }
        title = RoadUI.Core.decodeUri(title);
        //url = $.trim(url).substr(0, 1) == "/" ? rootdir + url : url;
        url += url.indexOf('?') >= 0 ? "&rf_appopenmodel=" + model : "?rf_appopenmodel=" + model;
        switch (parseInt(model)) {
            case 0:
                mainTab.addTab({ id: "tab_" + id.replaceAll('-', ''), title: title, src: url });
                break;
            case 1:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: false, openerid: openerId || "", opener: openerWindow || null, settopwindow: setTopWindow });
                break;
            case 2:
                mainDialog.open({ id: "window_" + id.replaceAll('-', ''), title: title, url: url, width: width || 800, height: height || 460, ismodal: true, openerid: openerId || "", opener: openerWindow || null, settopwindow: setTopWindow });
                break;
            case 3:
                RoadUI.Core.open(url + "&isopenwindow=1", width || 800, height || 460, title, openerWindow);
                break;
            case 4:
                try {
                    (openerWindow || window).showModalDialog(url + "&isopenwindow=1", null, "dialogWidth=" + (width || 800) + "px;dialogHeight=" + (height || 460) + "px;center=1");
                } catch (e) {
                    alert("您的浏览器不支持此打开方式!");
                }
                break;
            case 5:
                (openerWindow || window).open(url + "&isopenwindow=1");
                break;
        }
    }

    function switchMenu(div, t) {
        var $div = $(div).parent().parent().parent();
        if (0 == t) {
            $("#mainMenutd1").show(200);
            $("#mainMenutd").hide();
        }
        else if (1 == t) {
            $("#mainMenutd").show(200);
            $("#mainMenutd1").hide();
        }
        $.cookies.set("usermenutype", t, { expiresAt: new Date(2099, 1, 1) });
        $(".menulistdiv11sub").remove();
    }

    function changeTheme(themeName, isCng) {
        if (!themeName || themeName.toString().trim().length == 0) {
            themeName = $.cookies.get("rf_core_theme");
        }

        $("span[class^='mainTheme_']").each(function () {
            var cssName = $(this).attr("class");
            $(this).removeClass().addClass(cssName.replace("1", ""));

        });
        try {
            themeName = themeName.toLowerCase();
            var current = $(".mainTheme_" + themeName) || $(".mainTheme_" + themeName + "1");
            current.removeClass().addClass("mainTheme_" + themeName + "1");
        }
        catch (e) { }
        $.cookies.set("rf_core_theme", themeName, { expiresAt: new Date(2099, 1, 1) });
        if (isCng) {
            RoadUI.Core.allFrames = [];
            RoadUI.Core.getAllFrames();
            for (var i = 0; i < RoadUI.Core.allFrames.length; i++) {
                $("#style_style", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/RoadFlowResources/themes/" + themeName + "/style/style.css");
                $("#style_ui", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/RoadFlowResources/themes/" + themeName + "/style/ui.css");
                $("#grid_ui", RoadUI.Core.allFrames[i].document).attr("href", rootdir + "/RoadFlowResources/themes/" + themeName + "/jqgrid/jquery-ui.css");
                
            }
        }
    }

    function login() {
        openApp("/Home/Login1?issession=1", 2, "用户登录", "login", 400, 230, false, null, null, false);
    }

    //刷新一个页面
    function refreshPage(tabID) {
        if (!tabID) {
            tabID = 'tab_INDEX';
        }
        mainTab.refresh(tabID);
        tabID = 'tab_71D2B0D5B3884079BE88D6DC161C2639';//待办事项TAB
        mainTab.refresh(tabID);
    }
</script>
